package com.easy.controller;

import com.easy.bean.Schedule;
import com.easy.service.ScheduleService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("schedule")
public class ScheduleController {

    @Autowired
    ScheduleService scheduleService;

    @GetMapping("page")
    public Result page(Page page, Schedule schedule) {
        Object obj = scheduleService.page(page, schedule);
        return Result.success(obj);
    }

    @PostMapping
    public Result add(@RequestBody Schedule schedule) {
        Object obj = scheduleService.add(schedule);
        return Result.success(obj);
    }



    @PutMapping
    public Result edit(@RequestBody Schedule schedule) {
        Object obj = scheduleService.edit(schedule);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id) {
        Object obj = scheduleService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = scheduleService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Schedule schedule) {
        Object obj = scheduleService.all(schedule);
        return Result.success(obj);
    }
    // 优化时间段查询接口，明确接收doctor_id参数
    @GetMapping("allTimeSlot")
    public Result allTimeSlot(@RequestParam("doctor_id") Integer doctor_id) {
        Schedule schedule = new Schedule();
        schedule.setDoctor_id(doctor_id);
        Object obj = scheduleService.allTimeSlot(schedule);
        return Result.success(obj);
    }

    // 新增的分页接口：带医生名称
    @GetMapping("pageWithDoctor")
    public Result pageWithDoctor(Page page, Schedule sch) {
        Object obj = scheduleService.pageWithDoctor(page, sch);
        return Result.success(obj);
    }

}